﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _4_7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void LoadBackGround()
        {
            try
            {
                Bitmap backPic = new Bitmap("发射场.jpg");
                this.BackgroundImage = backPic;
                this.ClientSize = new Size(backPic.Width, backPic.Height);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"加载背景图片失败: {ex.Message}");
            }
        }

        private void InitRocket()
        {
            try
            {
                Bitmap pic = new Bitmap("火箭.gif");
                pictureBox2.Image = pic;
                pictureBox2.BackColor = Color.Transparent;
                pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
                pictureBox2.Size = new Size(pic.Width, pic.Height);
                pictureBox2.Left = this.ClientSize.Width / 2 - pictureBox2.Width / 2;
                pictureBox2.Top = this.ClientSize.Height - pictureBox2.Height + 100;
            }
            catch (Exception ex)
            {
                MessageBox.Show($"加载火箭图片失败: {ex.Message}");
            }
        }

        private void InitProgress()
        {
            progressBar1.Dock = DockStyle.Top;
            progressBar1.Maximum = pictureBox2.Top + pictureBox2.Height;
            progressBar1.Minimum = 0;
            progressBar1.Value = 0;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            LoadBackGround();
            InitRocket();
            InitProgress();

            timer1.Interval = 1; // 设置时钟频率为1ms
        }

        private void Form1_DoubleClick(object sender, EventArgs e)
        {
            if (!timer1.Enabled)
            {
                timer1.Enabled = true;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (pictureBox2.Top + pictureBox2.Height > 0)
            {
                pictureBox2.Top--; // 火箭上升
                progressBar1.Value++; // 进度条前进
            }
            else
            {
                timer1.Enabled = false;
                MessageBox.Show("火箭发射完成！");
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }
    }   
}

